import axios from "axios"
axios.defaults.baseURL="https://apis.netstart.cn/douguo"
// 添加请求拦截器
axios.interceptors.request.use(function (config) {
    // 在发送请求之前做些什么
    return config;
}, function (error) {
    // 对请求错误做些什么
    //关闭加载提示
  
    return Promise.reject(error);
});

// 添加响应拦截器
axios.interceptors.response.use(function (response) {
    // 对响应数据做点什么
    //关闭加载提示
   
    return response;
}, function (error) {
    // 对响应错误做点什么
    //关闭加载提示
   
    return Promise.reject(error);
});

//获取全局数据
export const getConfig:()=>any=():any=>{
    return axios({
        method:"GET",  
        url:"/config.json"
    })
}
//获取初始化主页面导航数据
export const getInit:()=>any=():any=>{
     return axios({
         method:"GET",  
         url:"/init.json"
     })
}


//获取关注列表
export const getFollowListAPI=(offset:number,limit:number )=>{
    return axios({
        url:`home/ffeeds/${offset}/${limit}`,
    })
}

//获取推荐列表
export const getRecommendListAPI=(offset:number,limit:number )=>{
    return axios({
        url:`home/recommended/${offset}/${limit}`,
    })
}

//获取笔记列表
export const getNoteListAPI=(offset:number,limit:number,index:number )=>{
    //第一页不填，之后页面依次添加上一页返回结果的btmid字段值
    if(index===0){
        return axios({
            url:`home/notes/${offset}/${limit}`,
        })
    }
    else{
        return axios({
            url:`home/notes/${offset}/${limit}??btmid=[11393964,30854435]`,
        })
    }
}

//获取视频列表
export const getVideoListAPI=(offset:number,limit:number)=>{
    return axios({
        url:`home/videos/${offset}/${limit}`,
    })
}

//获取活动列表
export const getActivityListAPI=(offset:number,limit:number)=>{
    return axios({
        url:`home/events/getlists?offset=${offset}limit=${limit}`,
    })
}



//获取菜谱分类数据
export const getFlatcatalogs:()=>any=():any=>{
    return axios({
        method:"GET",  
        url:"/douguo/flatcatalogs.json",
    })
}
//获取热门搜索关键字数据
export const getHotkeyword:()=>any=():any=>{
    return axios({
        method:"GET",  
        url:"/recipe/search/hot",
    })
}
//获取搜索关键字建议
export const getkeywordSugs:(kw:string)=>any=(kw:string):any=>{
    return axios({
        method:"GET",  
        url:"recipe/search/suggests",
        params:{
             kw
        }
    })
}
//获取推荐菜谱信息
export const getrecommendRecipes:(limit:number)=>any=(limit:number):any=>{
    return axios({
        method:"GET",  
        url:`home/recommended/0/${limit}`,
    })
}
//获取菜谱相关信息数据
export const getRecipes:(keyword:string,order?:number,offset?:number)=>any=(keyword:string,order?:number,offset?:number):any=>{
    return axios({
        method:"GET",  
        url:"recipe/search",
        params:{
             keyword,
             order,
             offset,
             limit:10
        }
    })
}
//获取菜谱详情
export const getMenuDetailToId = (menuId:string) => {
    return axios({
        method:'get',
        url:`/recipe/detail/${menuId}`,
    })
}


//获取菜谱评论列表
export const getrecipeReview = (userid:string) => {
    return axios({
        method:'get',
        url:`/recipe/flatcomments/${userid}/0/20`,
    })
}
// 收藏页面菜谱接口
// https://apis.netstart.cn/douguo/recipe/detail/3145896  接口
export const getCollectiondata:(id:string) => any = (id:string):any => {
    return axios ({
        method: 'get',
        url: `recipe/detail/${id}`,
    })
}
// 收藏页面笔记接口
export const getCookBookdata:(id:string) => any = (id:string):any => {
    return axios ({
        method: 'get',
        url: `note/detail/${id}`,
    })
}


// 用户信息
export const getUserDetails:(id:string)=>any= (id:string):any => {
    return axios ({
        method: 'get',
        url: `user/info/`+id,
    })
}
// 用户笔记
export const getUserNotesdata:(id:string,offset:number)=>any= (id:string,offset:number):any => {
    return axios ({
        method: 'get',
        url: `user/usernotescalendar/${id}/${offset}/${(offset+1)*20}`,
    })
}

// 用户菜谱
export const getCookbook:(id:string,offset:number)=>any= (id:string,offset:number):any => {
    return axios ({
        method: 'get',
        url: `user/urecipes/${id}/${offset}/${(offset+1)*20}`,
    })
}

// 用户收藏
export const getCollection:(id:string,offset:number)=>any= (id:string,offset:number):any => {
    return axios ({
        method: 'get',
        url: `user/ufavorites/${id}/${offset}/${(offset+1)*20}`,
    })
}
